package com.itheima.youdianda.interceptor;

import com.itheima.youdianda.utils.JwtUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FrameLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        if(token != null) {
            String id = JwtUtils.getClaims(token).get("id").toString();
            request.getSession().setAttribute("userId", id);
        }
        return true;

    }
}
